package com.tdkj.exception;

import java.io.IOException;
import java.sql.SQLException;

import org.springframework.dao.DataAccessException;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
/**
 * 

 * FileName:     ExceptionInterceptor.java

 * @Description: TODO异常拦截器

 * All rights Reserved, Designed By ZTE-ITS

 * Copyright:    Copyright(C) 2010-2011

 * Company       天成科技有限公司

 * @author:    李兴建

 * @version    V1.0 

 * Createdate:         2012-8-21 下午08:48:41

 *

 * Modification  History:

 * Date         Author        Version        Discription

 * -----------------------------------------------------------------------------------

 * 2012-8-21       李兴建          1.0             1.0

 * Why & What is modified: <修改原因描述>
 */
@SuppressWarnings("serial")
public class ExceptionInterceptor extends AbstractInterceptor {

	public String intercept(ActionInvocation actionInvocation) throws Exception {

		String result = "";

		try {

			result = actionInvocation.invoke();

		} catch (DataAccessException ex) {

			throw new SystemException("数据库操作失败！");

		} catch (NullPointerException ex) {

			throw new SystemException("空指针，调用了未经初始化或者是不存在的对象！");

		} catch (IOException ex) {

			throw new SystemException("IO读写异常！");

		} catch (ClassNotFoundException ex) {

			throw new SystemException("指定的类不存在！");

		} catch (ArithmeticException ex) {

			throw new SystemException("数学运算异常！");

		} catch (ArrayIndexOutOfBoundsException ex) {

			throw new SystemException("数组下标越界！");

		} catch (IllegalArgumentException ex) {

			throw new SystemException("调用方法的参数错误！");

		} catch (ClassCastException ex) {

			throw new SystemException("类型强制转换错误！");

		} catch (SecurityException ex) {

			throw new SystemException("违背安全原则异常！");

		} catch (SQLException ex) {

			throw new SystemException("操作数据库异常！");

		} catch (NoSuchMethodError ex) {

			throw new SystemException("调用了未定义的方法！");

		} catch (InternalError ex) {

			throw new SystemException("Java虚拟机发生了内部错误！");

		} catch (Exception ex) {

			throw new SystemException("程序内部错误，操作失败！");

		}

		return result;

	}

}